home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tags18.zip / WD.CB < prev    next >
Text File  |  1991-09-30  |  6KB  |  175 lines

  1. /*======================================================================*/
  2. /* where-defined       Leonid Kokin        9/26/1991                    */
  3. /*                                                                      */
  4. /*  Use: position cursor on a symbol and press <ctrl-w>                 */
  5. /*                                                                      */
  6. /* Comment: in order to have this macro loaded automatically when       */
  7. /*          Brief is entered, add the -mwd switch in your autoexec.bat  */
  8. /*          and place your wd.cm in the c:\brief\macros directory.      */
  9. /*                                                                      */
  10. /* DEFAULT_TAG_FILE = default name of the tag file being used. This is  */
  11. /*                    the name of the tag file that will come up first  */
  12. /*                    upon pressing <ctrl-w>. If, for example your tag  */
  13. /*                    file is xyz.tag, then you shoud #define it to be  */
  14. /*                    xyz below.                                        */
  15. /*                                                                      */
  16. /* PATH_ENV_VAR     = name of the environment variable containing the   */
  17. /*                    path to your source files. This will enable you   */
  18. /*                    to run this macro from any directory.             */
  19. /*                    Example: if your source files are in C:\SOURCES   */
  20. /*                    you must set an environment variable, say SRC,    */
  21. /*                    with SET SRC=C:\SOURCES in your autoexec.bat file */
  22. /*                    then #define PATH_ENV_VAR to be SRC.              */
  23. /*                                                                      */
  24. /* ALLOWABLES       = set of allowable characters. This macro highlights*/
  25. /*                    a token comprizing only of allowable characters.  */
  26. /*                    These have been preset for you to include the     */
  27. /*                    underscore (_), lower case letters (a-z), upper   */
  28. /*                    case letters (A-Z), and integers (0-9). You may   */
  29. /*                    want to add other characters to this list, such   */
  30. /*                    ?, $, etc.                                        */
  31. /*======================================================================*/
  32. /*                                                                      */
  33. /* Modify the variables below and the recompile with <alt-F10>.         */
  34. /*                                                                      */
  35. #define DEFAULT_TAG_FILE "???"
  36. #define PATH_ENV_VAR     "???"
  37. #define ALLOWABLES       "_a-zA-Z0-9"
  38. /*======================================================================*/
  39.  
  40. void goback();
  41. void goto_next_occurence();
  42. string prev_word();
  43. string grab_word();
  44.  
  45. int tag_buffer, curr_buff, row0, col0;
  46. string symbol0, prod;
  47.  
  48. wd()  /* assign keys */
  49. {
  50.   assign_to_key("<Ctrl-w>", "where_defined");
  51.   assign_to_key("<Ctrl-v>", "nothing");
  52.   assign_to_key("<Ctrl-r>", "nothing");
  53. }
  54.  
  55. where_defined()     /* call this macro when <ctrl-w> is pressed */
  56. {
  57.   string symbol, tag_file, line, line_no, file_name;
  58.   int tag_file_buffer, col, n = 0;
  59.  
  60.   pause_on_error(1);
  61.   inq_position(row0, col0);
  62.   if(first_time()) prod = DEFAULT_TAG_FILE;
  63.   if(get_parm(NULL, symbol0, "Enter symbol: ", NULL, grab_word()))
  64.       if(get_parm(NULL, prod, "Enter product: ", NULL, prod))
  65.           if(exist(tag_file=inq_environment(PATH_ENV_VAR)+prod+".TAG")) 
  66.           {
  67.             raise_anchor();
  68.             symbol = symbol0 + " ";
  69.             curr_buff = set_buffer(tag_file_buffer = create_buffer("tagfile", tag_file));
  70.             tag_buffer = create_buffer("tag2", NULL);
  71.             top_of_buffer();
  72.             while(search_fwd(symbol, 0))
  73.             {
  74.               inq_position(NULL, col);
  75.               if(col == 1)
  76.               {
  77.                 n++;
  78.                 line = read();
  79.                 down();
  80.                 set_buffer(tag_buffer);
  81.                 insert(line);
  82.                 set_buffer(tag_file_buffer);
  83.               }
  84.               else down();
  85.             }
  86.             set_buffer(tag_buffer);
  87.             top_of_buffer();
  88.             save_position();
  89.             set_buffer(curr_buff);
  90.             delete_buffer(tag_file_buffer);
  91.  
  92.             switch (n)
  93.             {
  94.               case 0: message("0 occurences found");
  95.               case 1: 
  96.               {
  97.                 assign_to_key("<Ctrl-r>", "goback");
  98.                 assign_to_key("<Ctrl-v>", "goto_next_occurence");
  99.                 goto_next_occurence();
  100.               }
  101.               default:
  102.               {
  103.                 beep();
  104.                 message("%d occurences, <ctrl-v>:view, <ctrl-r>:return", n);
  105.                 if(n != 0) 
  106.                 {
  107.                   assign_to_key("<Ctrl-v>", "goto_next_occurence");
  108.                   assign_to_key("<Ctrl-r>", "goback");
  109.                 }
  110.               }
  111.             }
  112.           }
  113.           else message("error: %s file does not exist", tag_file);
  114.  
  115.   raise_anchor();
  116. }
  117.  
  118. string grab_word()
  119. {
  120.   int col1, col2;
  121.  
  122.   if(search_string("[" + ALLOWABLES + "]", read(1)))
  123.   {
  124.     search_fwd("[~" + ALLOWABLES + "]");
  125.     left();
  126.     inq_position(NULL, col2);
  127.     drop_anchor(1);
  128.     search_back("[~" + ALLOWABLES + "]");
  129.     search_fwd("[" + ALLOWABLES + "]");
  130.     inq_position(NULL, col1);
  131.     return(read(col2 - col1 + 1));
  132.   }
  133.   else return("");
  134. }
  135.  
  136. string prev_word()
  137. {
  138.   string str = "<|[ \\t][~ \\t]+[ \\t\\n]";
  139.   return(trim(ltrim(read(search_back(str, 2) - 1))));
  140. }
  141.  
  142. void goto_next_occurence()
  143. {
  144.   int n1, n2, t1, t2, file_buff, line_no1, line_no2;
  145.   string file_name;
  146.  
  147.   set_buffer(tag_buffer);
  148.   restore_position();
  149.   search_fwd("[ ]\\c[~ ]");
  150.   n1 = index(read(), "(");
  151.   n2 = index(read(), ")");
  152.   file_name = substr(read(), 1, n1 - 1);
  153.   line_no1 = atoi(substr(read(), n1 + 1, n2 - n1 - 1)); 
  154.   beginning_of_line();
  155.   down();
  156.   if(trim(ltrim(read())) == "") top_of_buffer();
  157.   save_position();
  158.   edit_file(file_name);
  159.   goto_line(line_no1);
  160.   search_back("[<;][~\\n]@" + symbol0 + "[ \\t\\n]", 2, 0);
  161.   inq_position(line_no2);
  162.   if((line_no1-line_no2) > 20) goto_line(line_no1);
  163.   to_top();
  164.   display_file_name();
  165. }
  166.  
  167.  
  168. void goback()
  169. {
  170.   set_buffer(curr_buff);
  171.   attach_buffer(curr_buff);
  172.   move_abs(row0, col0);
  173.   display_file_name();
  174. }
  175.